function hideloading() {
    document.getElementById('loading-animation').style.display = 'none';
    //scrollbar fix
    var bottombar = document.getElementsByClassName('bottom-main-nav')[0].parentElement;
    var offsetTop = bottombar.offsetTop;
    var ulstream = document.getElementsByClassName('stream-menu')[0];
    ulstream.style.height = offsetTop - ulstream.offsetTop + 'px';
}

window.onresize = function(event) {
    //scrollbar fix
    var bottombar = document.getElementsByClassName('bottom-main-nav')[0].parentElement;
    var offsetTop = bottombar.offsetTop;
    var ulstream = document.getElementsByClassName('stream-menu')[0];
    ulstream.style.height = offsetTop - ulstream.offsetTop + 'px';
    $('.signal-preview').css('width', document.width - 570 + 'px');
}

function addClass(el, className) {
    el.className += ' ' + className;
}

function removeClass(el, className) {
    var elClass = ' ' + el.className + ' ';
    while (elClass.indexOf(' ' + className + ' ') != - 1)
        elClass = elClass.replace(' ' + className + ' ', '');
    el.className = elClass;
}

function expand(element) {
    addClass(element.previousSibling.previousSibling, 'hide');
    addClass(element, 'hide');
    removeClass(element.nextSibling.nextSibling, 'hide');
}

function ajaxLoad(url) {
    $.post(url,
            function(data, status) {
                $('#page-content').html(data);
            });
    $('#home-fix-style').remove();
}

function preview(url) {
    $('#signal-preview').attr('src', url);
    if ($('.close-preview').css('top') == '-35px') {
        $('.annotable-extra-container').hide();
        $('.mention-circle-holder').css('right', '76px');
        $('.mention-right-container').css('margin-right', '0px');
        $('.mention-right-content').css('margin-left', '0px');
        $('.list-viewport').css('width', '500px');
        $('.list-viewport').css('left', '70px');
        $('.viewport').css('overflow', 'hidden');
        $('.viewport').css('width', '0px');
        $('.left-nav').css('overflow', 'hidden');
        $('.left-nav').css('width', '70px');
        $('.signal-preview').css('width', document.width - 570 + 'px');
        $('.signal-preview').css('left', '570px');
        $('.close-preview').css('top', '0px');
    }
    //$("#signal-preview").contents().find("head").append("<script>window.onerror = function(data) { return true; }</script>");
}

function hidePreview() {
    if ($('.signal-preview').width() != 0) {
        $('#signal-preview').attr('src', "");
        $('.mention-circle-holder').css('right', '-34px');
        $('.mention-right-container').css('margin-right', '120px');
        $('.mention-right-content').css('margin-left', '110px');
        $('.list-viewport').css('width', '');
        $('.list-viewport').css('left', '340px');
        $('.viewport').css('overflow', '');
        $('.viewport').css('width', '');
        $('.left-nav').css('overflow', '');
        $('.left-nav').css('width', '340px');
        $('.signal-preview').css('width', '0px');
        $('.signal-preview').css('left', '100%');
        $('.annotable-extra-container').fadeIn();
        $('.close-preview').css('top', '-35px');
    }
}

hidePreview();

$(document).keyup(function(e) {
    if (e.keyCode == 27) {
        params = window.location.href.split('#')[1];
        view = params.plit('/')[0];
        if (String(view).toUpperCase() === 'STREAM')
            hidePreview();
    }   // esc
});

function loadScript(url, callback)
{
    // adding the script tag to the head as suggested before
    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = url;

    // then bind the event to the callback function 
    // there are several events for cross browser compatibility
    script.onreadystatechange = callback;
    script.onload = callback;

    // fire the loading
    head.appendChild(script);
}